<?php
/**
 * Ecma-262 5rd 7.7
 * 
 */
class Punctuator extends Token{
    
    const Punctuator = 0;
    const DivPunctuator = 1;
    
    public static $PunctuatorList = array(
        '{',     '}',     '(',     ')',      '[',     ']',
        '.',     ';',     ',',     '<',      '>',     '<=',
        '>=',    '==',    '!=',    '===',    '!==',
        '+',     '-',     '*',     '%',      '++',    '--',
        '<<',    '>>',    '>>>',   '&',      '|',     '^',
        '!',     '~',     '&&',    '||',     '?',     ':',
        '=',     '+=',    '-=',    '*=',     '%=',    '<<=',
        '>>=',   '>>>=',  '&=',    '|=',     '^='
    );
    
    public static $DivPunctuatorList = array(
        '/',     '/='
    );
    
    public function __construct($tokenType){
        parent::__construct ();
        $this->tokenType = $tokenType;
        
        switch ($tokenType)
        {
        case Token::Punctuator_LeftBrace:
            $this->tokenLiteral = '{';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_RightBrace:
            $this->tokenLiteral = '}';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_LeftParenthesis:
            $this->tokenLiteral = '(';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_RightParenthesis:
            $this->tokenLiteral = ')';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_LeftSquareBrace:
            $this->tokenLiteral = '[';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_RightSquareBrace:
            $this->tokenLiteral = ']';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_Dot:
            $this->tokenLiteral = '.';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_Semicolon:
            $this->tokenLiteral = ';';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_Comma:
            $this->tokenLiteral = ',';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_Add:
            $this->tokenLiteral = '+';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_AddAdd:
            $this->tokenLiteral = '++';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_AddEqual:
            $this->tokenLiteral = '+=';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_Minus:
            $this->tokenLiteral = '-';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_MinusMinus:
            $this->tokenLiteral = '--';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_MinusEqual:
            $this->tokenLiteral = '-=';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_Asterisk:
            $this->tokenLiteral = '*';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_AsteriskEqual:
            $this->tokenLiteral = '*=';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_Percent:
            $this->tokenLiteral = '%';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_PercentEqual:
            $this->tokenLiteral = '%=';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_And:
            $this->tokenLiteral = '&';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_AndAnd:
            $this->tokenLiteral = '&&';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_AndEqual:
            $this->tokenLiteral = '&=';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_Or:
            $this->tokenLiteral = '|';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_OrOr:
            $this->tokenLiteral = '||';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_OrEqual:
            $this->tokenLiteral = '|=';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_Less:
            $this->tokenLiteral = '<';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_LessEqual:
            $this->tokenLiteral = '<=';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_LessLess:
            $this->tokenLiteral = '<<';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_LessLessEqual:
            $this->tokenLiteral = '<<=';
            $this->tokenLength = 3;
            break;
        case Token::Punctuator_More:
            $this->tokenLiteral = '>';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_MoreEqual:
            $this->tokenLiteral = '>=';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_MoreMore:
            $this->tokenLiteral = '>>';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_MoreMoreMore:
            $this->tokenLiteral = '>>>';
            $this->tokenLength = 3;
            break;
        case Token::Punctuator_MoreMoreEqual:
            $this->tokenLiteral = '>>=';
            $this->tokenLength = 3;
            break;
        case Token::Punctuator_MoreMoreMoreEqual:
            $this->tokenLiteral = '>>>=';
            $this->tokenLength = 4;
            break;
        case Token::Punctuator_ExclusiveOr:
            $this->tokenLiteral = '^';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_ExclusiveOrEqual:
            $this->tokenLiteral = '^=';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_Not:
            $this->tokenLiteral = '!';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_NotEqual:
            $this->tokenLiteral = '!=';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_NotEqualEqual:
            $this->tokenLiteral = '!==';
            $this->tokenLength = 3;
            break;
        case Token::Punctuator_Ask:
            $this->tokenLiteral = '?';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_Colon:
            $this->tokenLiteral = ':';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_Equal:
            $this->tokenLiteral = '=';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_EqualEqual:
            $this->tokenLiteral = '==';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_EqualEqualEqual:
            $this->tokenLiteral = '===';
            $this->tokenLength = 3;
            break;
        case Token::Punctuator_Division:
            $this->tokenLiteral = '/';
            $this->tokenLength = 1;
            break;
        case Token::Punctuator_DivisionEqual:
            $this->tokenLiteral = '/=';
            $this->tokenLength = 2;
            break;
        case Token::Punctuator_BitNot:
            $this->tokenLiteral = '~';
            $this->tokenLength = 1;
            break;
        }
    }
    
    /**
     * 
     * @param string $char
     */
    public static function isPunctuatorStart($char){
        static $punctuatorStartList = array(
            '{',    
            '}',    
            '(',    
            ')',    
            '[',    
            ']',    
            '.',    
            ';',    
            ',',    
            '+',    // ++    +=
            '-',    // --    -=
            '*',    //       *=
            '%',    //       %=
            '&',    // &&    &=
            '|',    // ||    |=
            '<',    // <=    <<    <<=
            '>',    // >=    >>    >>>    >>=    >>>=
            '^',    // ^=
            '!',    // !=    !==
            '~',    
            '?',    
            ':',    
            '=',    // ==    ===
            '/',    // /=
        );
        
        if(in_array($char, $punctuatorStartList)){
            return true;
        }
        
        return false;
    }
}